package com.czy.owner.utils;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.SelectOrderDetailsModel;
import com.czy.owner.rxbus.RxBus;
import com.czy.owner.rxbus.event.CommonEvent;
import com.czy.owner.ui.store.OnLineOrderActivity2;
import com.czy.owner.ui.workorder.SubscribeOrdelActivity2;

/**
 * Created by hedepu on 2017-09-04
 */

public class DialogUtils {
    //返回提示
    public static void showDateSuccessDialog(final Context context, final String type, String contentText, String cancleText, String sureText) {
        final Dialog mDateSuccessDialog;
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display mDisplay = windowManager.getDefaultDisplay();
        mDateSuccessDialog = new Dialog(context, R.style.AlertDialogStyle);
        View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_order_back_toast, null);
        TextView content_tv = (TextView) dialogView.findViewById(R.id.content_tv);

        Button btnSure = (Button) dialogView.findViewById(R.id.btn_sure);
        Button btnCancel = (Button) dialogView.findViewById(R.id.btn_cancel);
        mDateSuccessDialog.setContentView(dialogView);
        content_tv.setText(contentText);
        btnSure.setText(sureText);
        btnCancel.setText(cancleText);
        btnSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDateSuccessDialog.dismiss();

            }
        });
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("1".equals(type)) {
                    RxBus.getDefault().post(new CommonEvent("放弃支付"));
                    context.startActivity(new Intent(context, SubscribeOrdelActivity2.class).putExtra("currentId", 1));
                }
                ((Activity) context).finish();

            }
        });
        Window dialogWindow = mDateSuccessDialog.getWindow();
        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (mDisplay.getWidth() * 0.86);
        dialogWindow.setAttributes(p);
        mDateSuccessDialog.setCancelable(false);

        mDateSuccessDialog.show();
    }
}
